package cn.zjj.pet.service.impl;

import cn.zjj.basic.service.impl.BaseServiceImpl;
import cn.zjj.pet.domain.Pet;
import cn.zjj.pet.mapper.PetDetailMapper;
import cn.zjj.pet.mapper.PetMapper;
import cn.zjj.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {
    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void insert(Pet pet) {
        petMapper.insert(pet);
        pet.getPetDetail().setPet_id(pet.getId());
        petDetailMapper.insert(pet.getPetDetail());
    }


    @Override
    public void update(Pet pet) {
        petMapper.update(pet);

        petDetailMapper.update(pet.getPetDetail());
    }

    @Override
    public void delete(Long id) {
        petDetailMapper.delete(id);

        petMapper.delete(id);
    }


    //上架
    @Override
    public void onsale(List<Long> ids){
        //上架之前应该还有审核程序
        Date onsaletime = new Date();
        petMapper.onsale(ids,onsaletime);
    }

    @Override
    public void offsale(List<Long> ids) {
        Date offsaletime = new Date();
        petMapper.offsale(ids,offsaletime);
    }

}
